home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / scripts / plot / __pltopt__.m < prev    next >
Text File  |  1997-07-10  |  7KB  |  256 lines

  1. ## Copyright (C) 1996, 1997 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## usage: fmt = __pltopt__ (caller, opt)
  21. ##
  22. ## Decode plot option strings.
  23. ##
  24. ## If OPT is a valid option string, return a string of the form "w l 2"
  25. ## ("with lines 2").  Uses abbreviations for the options to avoid
  26. ## overrunning gnuplot's command line buffer unnecessarily.
  27. ##
  28. ## OPT can currently be some combination of the following:
  29. ##
  30. ##   "-"   for lines plot style (default).
  31. ##   "."   for dots plot style.
  32. ##   "@"   for points plot style.
  33. ##   "-@"  for linespoints plot style.
  34. ##   "^"   for impulses plot style.
  35. ##   "L"   for steps plot style.
  36. ##   "#"   for boxes plot style.
  37. ##   "~"   for errorbars plot style.
  38. ##   "#~"  for boxerrorbars plot style.
  39. ##   "n"   with n in 1-6 (wraps at 8), plot color
  40. ##   "nm"  with m in 1-6 (wraps at 6), point style (only valid for "@" or "-@")
  41. ##   "c"   where c is one of ["r", "g", "b", "m", "c", "w"] colors.
  42. ##   ";title;" where "title" is the label for the key.
  43. ##
  44. ##   Special points formats:
  45. ##
  46. ##      "+", "*", "o", "x" will display points in that style for term x11.
  47. ##
  48. ##   The legend may be fixed to include the name of the variable
  49. ##   plotted in some future version of Octave.
  50. ##
  51. ##   The colors, line styles, and point styles have the following
  52. ##   meanings for X11 and Postscript terminals under Gnuplot 3.6.
  53. ##
  54. ##   Number ------ Color -------  Line Style      ---- Points Style ----   
  55. ##          x11       postscript  postscript      x11         postscript   
  56. ##   =====================================================================
  57. ##     1    red       green       solid           "o"         "+"         
  58. ##     2    green     blue        long dash       "+"         "x"         
  59. ##     3    blue      red         short dash     square       "*"         
  60. ##     4    magenta   magenta     dotted          "x"        open square  
  61. ##     5    cyan      cyan        dot long dash  triangle    filled square
  62. ##     6    brown     yellow      dot short dash  "*"         "o"         
  63.  
  64. ## Author: Rick Niles <niles@axp745.gsfc.nasa.gov>
  65. ## Adapted-By: jwe
  66. ## Maintainer: jwe
  67.  
  68. function fmt = __pltopt__ (caller, opt)
  69.  
  70.   set_color = 0;
  71.   set_symbol = 0;
  72.   set_lines = 0;
  73.   set_dots = 0;
  74.   set_points = 0;
  75.   set_impulses = 0;
  76.   set_steps = 0;
  77.   set_boxes = 0;
  78.   set_errbars = 0;
  79.   set_key = 0;
  80.   more_opts = 1;
  81.  
  82.   WITH = "w";
  83.   LINES = "l";
  84.   LINESPOINTS = "linesp";
  85.   BOXERRORBARS = "boxer";
  86.   BOXES = "boxes";
  87.   POINTS = "p";
  88.   DOTS = "d";
  89.   IMPULSES = "i";
  90.   STEPS = "s";
  91.   ERRORBARS = "e";
  92.   TITLE = "title";
  93.  
  94.   if (nargin != 2)
  95.     usage ("__pltopt__ (opt)");
  96.   endif
  97.  
  98.   if (! isstr (opt))
  99.     error ("__pltopt__: argument must be a string");
  100.   endif
  101.  
  102.   while (more_opts)
  103.  
  104.     ## First get next char.
  105.  
  106.     if (max (size (opt)) > 1)
  107. #      [char, opt] = sscanf (opt, "%c %s", "C");
  108.        char = opt(1);
  109.        opt = opt(2:length(opt));
  110.     else
  111.       char = opt;
  112.       more_opts = 0;
  113.     endif
  114.  
  115.     ## Now set flags based on char.
  116.  
  117.     if (strcmp (char, "-"))
  118.       set_lines = 1;
  119.     elseif (strcmp (char, "."))
  120.       set_dots  = 1;
  121.     elseif (strcmp (char, "@"))
  122.       set_points = 1;
  123.     elseif (strcmp (char, "^"))
  124.       set_impulses = 1;
  125.     elseif (strcmp (char, "L"))
  126.       set_steps = 1;
  127.     elseif (strcmp (char, "~"))
  128.       set_errbars = 1;
  129.     elseif (strcmp (char, "#"))
  130.       set_boxes = 1;
  131.     elseif (strcmp (char, "0") || strcmp (char, "1") ...
  132.             || strcmp (char, "2") || strcmp (char, "3") ...
  133.             || strcmp (char, "4") || strcmp (char, "5") ...
  134.             || strcmp (char, "6") || strcmp (char, "7") ...
  135.             || strcmp (char, "8") || strcmp (char, "9"))
  136.       if (set_color)
  137.     set_points = 1;
  138.     symbol = char;
  139.     set_symbol = 1;
  140.       else
  141.     color = char;
  142.     set_color = 1;
  143.       endif
  144.     elseif (strcmp (char, "r"))
  145.       set_color = 1;
  146.       color = "1";
  147.     elseif (strcmp (char, "g"))
  148.       set_color = 1;
  149.       color = "2";
  150.     elseif (strcmp (char, "b"))
  151.       set_color = 1;
  152.       color = "3";
  153.     elseif (strcmp (char, "m"))
  154.       set_color = 1;
  155.       color = "4";
  156.     elseif (strcmp (char, "c"))
  157.       set_color = 1;
  158.       color = "5";
  159.     elseif (strcmp (char, "w"))
  160.       set_color = 1;
  161.       color = "6";
  162.     elseif (strcmp (char, "*"))
  163.       set_points = 1;
  164.       set_symbol = 1;
  165.       symbol = "6";
  166.     elseif (strcmp (char, "+"))
  167.       set_points = 1;
  168.       set_symbol = 1;
  169.       symbol = "2";
  170.     elseif (strcmp (char, "o"))
  171.       set_points = 1;
  172.       set_symbol = 1;
  173.       symbol = "1";
  174.     elseif (strcmp (char, "x"))
  175.       set_points = 1;
  176.       set_symbol = 1;
  177.       symbol = "4";
  178.     elseif (strcmp (char, ";"))  # title mode.
  179.       set_key = 1;
  180.       working = 1;
  181.       key_title = ""; 
  182.       while (working)
  183.         if (max (size (opt)) > 1)
  184.       char = opt(1);
  185.       opt = opt(2:length(opt));
  186.         else
  187.       char = opt;
  188.       if (! strcmp (char, ";"))
  189.             error ("%s: unfinished key label", caller);
  190.           end
  191.           more_opts = 0;
  192.           working = 0;
  193.         endif
  194.         if strcmp (char, ";")
  195.           working = 0;
  196.         else
  197.       if (isempty (key_title))  # needs this to avoid empty matrix warning.
  198.             key_title = char;
  199.       else
  200.             key_title = strcat (key_title, char);
  201.       endif
  202.         endif
  203.       endwhile
  204.     elseif (strcmp (char, " ")) 
  205.       ## whitespace -- do nothing.
  206.     else
  207.       error ("%s: unrecognized format character: '%s'", caller, char);
  208.     endif
  209.   endwhile
  210.  
  211.   ## Now create format string.
  212.  
  213.   fmt = WITH;
  214.  
  215.   if (set_lines)
  216.     if (set_points)
  217.       fmt = strcat (fmt, " ", LINESPOINTS);
  218.     else
  219.       fmt = strcat (fmt, " ", LINES);
  220.     endif
  221.   elseif (set_boxes)
  222.     if (set_errbars)
  223.       fmt = strcat (fmt, " ", BOXERRORBARS);
  224.     else
  225.       fmt = strcat (fmt, " ", BOXES);
  226.     endif
  227.   elseif (set_points)
  228.     fmt = strcat (fmt, " ", POINTS);
  229.   elseif (set_dots)
  230.     fmt = strcat (fmt, " ", DOTS);
  231.   elseif (set_impulses)
  232.     fmt = strcat (fmt, " ", IMPULSES);
  233.   elseif (set_steps)
  234.     fmt = strcat (fmt, " ", STEPS);
  235.   elseif (set_errbars)
  236.     fmt = strcat (fmt, " ", ERRORBARS);
  237.   endif
  238.  
  239.   if (strcmp (fmt, WITH))
  240.     fmt = strcat (fmt, " ", LINES);
  241.   endif
  242.  
  243.   if (set_color)
  244.     fmt = strcat (fmt, " ", color);
  245.     if (set_symbol)
  246.       fmt = strcat (fmt, " ", symbol);
  247.     endif
  248.   elseif (set_symbol)
  249.     fmt = strcat (fmt, " 1 ", symbol);
  250.   endif
  251.  
  252.   if (set_key)
  253.     fmt = strcat (fmt, " ", TITLE, ' "', key_title, '" ');
  254.   endif
  255. endfunction
  256.